var Variable = function(varName) {
        this.type = 'variable';
        this.name = varName;
        this.value = 'unknow';
    }
    //这里我们不记录值！！！只记录作用域和变量名


    //递归进行变量的提取
exports.createVarTree = function(words, groupId, type) { //建好反映作用域的变量树
    var varGroup = {
        type: '',
        id: 0,
        variables: []
    }
    var inFor = false;
    var inIf = false;
    var inWhile = false;
    var temp = [];
    var leftBraceNum = 0;
    var rightBraceNum = 0;
    var id = 0;
    for (var Key in words) {
        var key = parseInt(Key);
        if (words[key] === 'for' && !inIf && !inFor && !inWhile) {
            id = key;
            inFor = true;
        }
        if ((words[key] === 'if' || words[key] === 'else') && !inIf && !inFor && !inWhile) {
            id = key;
            inIf = true;
        }
        if (words[key] === 'while' && !inIf && !inFor && !inWhile) {
            id = key;
            inWhile = true;
        }
        if (inIf) {
            if (words[key] === '{') {
                leftBraceNum++;
            }
            if (words[key] === '}') {
                rightBraceNum++;
            }
            if (key !== id) {
                temp.push(words[key]);
            }
            if (leftBraceNum > 0 && leftBraceNum === rightBraceNum) {
                varGroup.variables.push(exports.createVarTree(temp, id, 'if'))
                temp = [];
                leftBraceNum = 0;
                rightBraceNum = 0;
                inIf = false;
            }
            continue;
        }
        if (inWhile) {
            if (words[key] === '{') {
                leftBraceNum++;
            }
            if (words[key] === '}') {
                rightBraceNum++;
            }
            if (key !== id) {
                temp.push(words[key]);
            }
            if (leftBraceNum > 0 && leftBraceNum === rightBraceNum) {
                varGroup.variables.push(exports.createVarTree(temp, id, 'while'))
                temp = [];
                leftBraceNum = 0;
                rightBraceNum = 0;
                inWhile = false;
            }
            continue;
        }
        if (inFor) {
            if (words[key] === '{') {
                leftBraceNum++;
            }
            if (words[key] === '}') {
                rightBraceNum++;
            }
            if (key !== id) {
                temp.push(words[key]);
            }
            if (leftBraceNum > 0 && leftBraceNum === rightBraceNum) {
                varGroup.variables.push(exports.createVarTree(temp, id, 'for'))
                temp = [];
                leftBraceNum = 0;
                rightBraceNum = 0;
                inFor = false;
            }
            continue;
        }
        if (words[key] === 'set') {
            var variable = new Variable(words[key + 1]);
            varGroup.variables.push(variable);
        }
    }
    varGroup.id = groupId;
    varGroup.type = type;
    return varGroup;
}
